home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / xmmlrg.exe / XMMTEST.C < prev   
C/C++ Source or Header  |  1991-09-05  |  9KB  |  284 lines

  1. /*************************************************************************
  2. *                                                                        *
  3. *     Test Program for the XMMHLDLR package                                             *
  4. *                                                                        *
  5. *************************************************************************/
  6.  
  7. #ifndef    LINT_ARGS
  8. #define    LINT_ARGS
  9. #endif
  10.  
  11. #ifndef    ANSI
  12. #define    ANSI
  13. #endif
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "prebelif.h"
  19.  
  20. #include "xmmhndlr.h"
  21.  
  22. /*************************************************************************
  23. *                                                                        *
  24. *     Local Defines                                                                             *
  25. *                                                                        *
  26. *************************************************************************/
  27.  
  28. #define    S_OKAY    0
  29. #define    S_NOTFOUND    2
  30.  
  31. #define    TRUE    1
  32. #define    FALSE    0
  33.  
  34. #define    NUM_HANDLES    12
  35. #define    MAX_RECS        2000
  36. #define    RECSIZE        128
  37. #define    RECSIZE_INT    (RECSIZE/2)
  38.  
  39. /*************************************************************************
  40. *                                                                        *
  41. *     Fucntion Prototypes                                                                     *
  42. *                                                                        *
  43. *************************************************************************/
  44.  
  45. int main(void);
  46. void  Fill(int  *ptr,int  pattern,int  count);
  47. int  Cmp(int  *ptr1,int  *ptr2,int  count);
  48. void PutRecs(XHandle hnd, int type);
  49. void GetCmpRecs(XHandle hnd);
  50. void GetExistRecs(XHandle hnd);
  51.  
  52. /*************************************************************************
  53. *                                                                        *
  54. *     Main line                                                                                 *
  55. *                                                                        *
  56. *************************************************************************/
  57.  
  58. int main()
  59. {
  60.     int i;
  61.     XHandle hnd_tab[NUM_HANDLES];
  62.     int status;
  63.  
  64.     if (InitXMMSystem(NUM_HANDLES) != S_OKAY)    /* do an init */
  65.         {
  66.         printf("InitXMMSystem failed\n");
  67.         return(1);
  68.         }
  69.  
  70.     printf("Init was successful\n");
  71.  
  72. /*************************************************************************
  73. *                                                                        *
  74. *     Alocate Tables                                                                             *
  75. *                                                                        *
  76. *************************************************************************/
  77.  
  78.     for (i=0; i < NUM_HANDLES; i++)
  79.         {
  80.         hnd_tab[i] = AllocateXMMArea((long)MAX_RECS, RECSIZE);
  81.         if (hnd_tab[i] < 0)                            /* fail?? */
  82.             {
  83.             printf("Allocate area %d failed - ret=%d code=%x\n",
  84.                         i, hnd_tab[i], XMMErrorCode);
  85.             return(1);
  86.             }
  87.         }
  88.  
  89.     printf("Allocation of %d XMM Areas was successful\n", NUM_HANDLES);
  90.  
  91. /*************************************************************************
  92. *                                                                        *
  93. *     Test Put / Record exists check with null records                              *
  94. *                                                                        *
  95. *************************************************************************/
  96.  
  97.     for (i=0; i < NUM_HANDLES; i++)
  98.         {
  99.         PutRecs(hnd_tab[i], FALSE);
  100.         }
  101.  
  102.     printf("Record Puts (NULL) on %d XMM Areas completed\n", NUM_HANDLES);
  103.  
  104.     for (i=0; i < NUM_HANDLES; i++)
  105.         {
  106.         GetExistRecs(hnd_tab[i]);
  107.         }
  108.  
  109.     printf("Record Exists from %d XMM Areas completed\n", NUM_HANDLES);
  110.  
  111. /*************************************************************************
  112. *                                                                        *
  113. *     Test Put / Get Record                                                                 *
  114. *                                                                        *
  115. *************************************************************************/
  116.  
  117.     for (i=0; i < NUM_HANDLES; i++)
  118.         {
  119.         PutRecs(hnd_tab[i], TRUE);
  120.         }
  121.  
  122.     printf("Record Puts on %d XMM Areas completed\n", NUM_HANDLES);
  123.  
  124.     for (i=0; i < NUM_HANDLES; i++)
  125.         {
  126.         GetCmpRecs(hnd_tab[i]);
  127.         }
  128.  
  129.     printf("Record Gets from %d XMM Areas completed\n", NUM_HANDLES);
  130.  
  131. /*************************************************************************
  132. *                                                                        *
  133. *     Deallocate Tables                                                                         *
  134. *                                                                        *
  135. *************************************************************************/
  136.  
  137.     for (i=0; i < NUM_HANDLES; i++)
  138.         {
  139.         status = DeAllocateXMMArea(hnd_tab[i]);
  140.         if (status != S_OKAY)                        /* fail?? */
  141.             {
  142.             printf("DeAllocate area %d failed - ret=%d code=%x\n",
  143.                         i, status, XMMErrorCode);
  144.             return(1);
  145.             }
  146.         }
  147.  
  148.     printf("Deallocation of %d XMM Areas was successful\n", NUM_HANDLES);
  149.  
  150. /*************************************************************************
  151. *                                                                        *
  152. *     Shut Down                                                                                 *
  153. *                                                                        *
  154. *************************************************************************/
  155.  
  156.     if (ShutXMMSystem() != S_OKAY)
  157.         {
  158.         printf("ShutXMMSystem failed\n");
  159.         return(1);
  160.         }
  161.  
  162.     printf("Shut was successful\n");
  163.  
  164.     return(0);
  165.  
  166. }
  167.  
  168. /*<f>*/
  169. void PutRecs(XHandle hnd, int type)
  170. /*************************************************************************
  171. *                                                                        *
  172. *     Fill each record of this XMM area with a record based on recno             *
  173. *                                                                        *
  174. *************************************************************************/
  175. {
  176.     int record[RECSIZE_INT];
  177.     int i;
  178.     int status;
  179.  
  180.     for (i=0; i < MAX_RECS; i++)
  181.         {
  182.         if (type == TRUE)
  183.             Fill(record, i, RECSIZE_INT);
  184.         else
  185.             memset((char *)record, '\0', sizeof(record));
  186.  
  187.         status = PutXMMRecord(hnd, (long)i, record);
  188.         if (status != S_OKAY)
  189.             {
  190.             printf("Put in area %d failed for record %d- ret=%d code=%x\n",
  191.                         hnd, i, status, XMMErrorCode);
  192.             return;
  193.             }
  194.  
  195.         }
  196. }
  197.  
  198. void GetCmpRecs(XHandle hnd)
  199. /*************************************************************************
  200. *                                                                        *
  201. *     Get each record of this XMM area and compare with what we put             *
  202. *                                                                        *
  203. *************************************************************************/
  204. {
  205.     int record[RECSIZE_INT];
  206.     int cmp_rec[RECSIZE_INT];
  207.     int i;
  208.     int status;
  209.  
  210.     for (i=0; i < MAX_RECS; i++)
  211.         {
  212.         Fill(cmp_rec, i, RECSIZE_INT);            /* fill what we put */
  213.         status = GetXMMRecord(hnd, (long)i, record);
  214.         if (status != S_OKAY)
  215.             {
  216.             printf("Get in area %d failed for record %d- ret=%d code=%x\n",
  217.                         hnd, i, status, XMMErrorCode);
  218.             return;
  219.             }
  220.  
  221.         if (Cmp(record, cmp_rec, RECSIZE_INT))    /* compare what we got */
  222.             {
  223.             printf("Compare Failed in area %d failed for record %d\n", hnd, i);
  224.             return;
  225.             }
  226.  
  227.  
  228.  
  229.         }
  230.  
  231. }
  232.  
  233. void GetExistRecs(XHandle hnd)
  234. /*************************************************************************
  235. *                                                                        *
  236. *     See if each record in this XMM area exists - it should not                *
  237. *                                                                        *
  238. *************************************************************************/
  239. {
  240.     int record[RECSIZE_INT];
  241.     int cmp_rec[RECSIZE_INT];
  242.     int i;
  243.     int status;
  244.  
  245.     for (i=0; i < MAX_RECS; i++)
  246.         {
  247.         status = CheckXMMRecord(hnd, (long)i);
  248.         if (status != S_NOTFOUND)
  249.             {
  250.             printf("Check in area %d failed for record %d- ret=%d code=%x\n",
  251.                         hnd, i, status, XMMErrorCode);
  252.             return;
  253.             }
  254.  
  255.         }
  256.  
  257. }
  258.  
  259. /*<f>*/
  260. void  Fill(int  *ptr,int  pattern,int  count)
  261. /*************************************************************************
  262. *                                                                        *
  263. *     Fill a word area with a pattern based on a